package com.qilu.pe.ui.activity;

import android.os.Bundle;

import com.androidkun.xtablayout.XTabLayout;
import com.qilu.pe.R;
import com.qilu.pe.base.Base2Activity;
import com.qilu.pe.ui.fragment.ExpertExplainFragment;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

// 专家解读
public class ExpertExplainActivity extends Base2Activity {
    private XTabLayout tab_2;
    private ViewPager vp_tab;

    public static final String[] HOME_MODELS = {"已解读", "待解读"};
    private TestStatusAdapter vpTabAdapter;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_expert_explain;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        tab_2 = findViewById(R.id.tab_2);
        vp_tab = findViewById(R.id.vp_tab);

        setNavigationIcon(R.mipmap.ic_left_arrow);

        setHeadTitle("专家解读");

        for (int i = 0; i < 2; i++) {
            tab_2.addTab(tab_2.newTab().setText(HOME_MODELS[i]), i);
        }
        vpTabAdapter = new TestStatusAdapter(getSupportFragmentManager());
        vp_tab.setAdapter(vpTabAdapter);
        tab_2.setupWithViewPager(vp_tab);
    }

    private class TestStatusAdapter extends FragmentPagerAdapter {

        public TestStatusAdapter(@NonNull FragmentManager fm) {
            super(fm);
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return ExpertExplainFragment.newInstance("1");
            } else if (position == 1) {
                return ExpertExplainFragment.newInstance("0");
            }
            return ExpertExplainFragment.newInstance("1");
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return HOME_MODELS[position];
        }
    }
}